package com.healthyeating.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.Sport;
import com.healthyeating.manage.service.ISportService;
import com.healthyeating.common.utils.poi.ExcelUtil;
import com.healthyeating.common.core.page.TableDataInfo;

/**
 * 运动打卡Controller
 * 
 * @author 段奇乐
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/manage/sport")
public class SportController extends BaseController
{
    @Autowired
    private ISportService sportService;

    /**
     * 查询运动打卡列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sport:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sport sport)
    {
        startPage();
        List<Sport> list = sportService.selectSportList(sport);
        return getDataTable(list);
    }

    /**
     * 导出运动打卡列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sport:export')")
    @Log(title = "运动打卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sport sport)
    {
        List<Sport> list = sportService.selectSportList(sport);
        ExcelUtil<Sport> util = new ExcelUtil<Sport>(Sport.class);
        util.exportExcel(response, list, "运动打卡数据");
    }

    /**
     * 获取运动打卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sport:query')")
    @GetMapping(value = "/{sportId}")
    public AjaxResult getInfo(@PathVariable("sportId") Long sportId)
    {
        return success(sportService.selectSportBySportId(sportId));
    }

    /**
     * 新增运动打卡
     */
    @PreAuthorize("@ss.hasPermi('manage:sport:add')")
    @Log(title = "运动打卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sport sport)
    {
        return toAjax(sportService.insertSport(sport));
    }

    /**
     * 修改运动打卡
     */
    @PreAuthorize("@ss.hasPermi('manage:sport:edit')")
    @Log(title = "运动打卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sport sport)
    {
        return toAjax(sportService.updateSport(sport));
    }

    /**
     * 删除运动打卡
     */
    @PreAuthorize("@ss.hasPermi('manage:sport:remove')")
    @Log(title = "运动打卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sportIds}")
    public AjaxResult remove(@PathVariable Long[] sportIds)
    {
        return toAjax(sportService.deleteSportBySportIds(sportIds));
    }
}
